/*
 * @Author: TT-hzy 
 * @Date: 2024-05-05 16:19:07
 * @LastEditors: TT-hzy 
 * @LastEditTime: 2024-05-05 17:02:05
 * @Description: 
 */

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hzy_normal_tool/hzy_normal_tool.dart';
import '../base_ui_config/base_state_widget.dart';
import '../config/theme_config/color_config.dart';
import '../utils/screen_utils.dart';
import 'compontents.dart';

enum CommonPlaceHoldType {
  /// 无网络
  noNetwork,

  /// 未登录
  noLogin,

  ///空数据
  emptyData,
}

class CommonPlaceHoldPage extends StatefulWidget {
  const CommonPlaceHoldPage({
    super.key,
    required this.placeHoldType,
    this.onTap,
    this.btnMsg,
    this.title,
    this.msg,
  });
  final CommonPlaceHoldType placeHoldType;
  final String? msg;
  final String? title;
  final String? btnMsg;
  final Function? onTap;
  @override
  State<StatefulWidget> createState() {
    return _CommonPlaceHoldPageState();
  }
}

class _CommonPlaceHoldPageState extends BaseStateWidget<CommonPlaceHoldPage> {
  /// 属性
  ///
  ///

  @override
  Widget createBody({
    required BuildContext context,
    BoxConstraints? constraints,
  }) {
    return Container(
      decoration: BoxDecoration(
        color: ColorConfig.scaffoldBackGroundColor.withAlpha(0),
      ),
      alignment: Alignment.center,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          configPlaceWidget(type: 1),
          Gaps.vGap15,
          configPlaceWidget(type: 2),
          Gaps.vGap15,
          configPlaceWidget(type: 4),
        ],
      ),
    );
  }

  /// 创建暂位图
  Widget createPlaceImageWidget() {
    Widget body = configEmptyDataWidget();
    return body;
  }

  /// 创建暂位图标语
  Widget createPlaceTitleWidget() {
    String title = "";
    if (widget.placeHoldType == CommonPlaceHoldType.noNetwork) {
      title = "暂无网络,请稍后重试";
    } else if (widget.placeHoldType == CommonPlaceHoldType.emptyData) {
      title = "暂无数据";
    }
    title = widget.msg ?? title;
    return Text(
      title,
      style: HzyTextStyle.fontMedium(
        size: 14.sp,
        color: HzyNormalColorS.col333333,
      ),
      textAlign: TextAlign.center,
    );
  }

  /// 创建暂位图描述语
  Widget createPlaceMessageWidget() {
    return Container();
  }

  /// 创建暂位图 刷新按钮
  Widget createPlaceReloadBtnWidget() {
    return InkWell(
      onTap: () async {
        widget.onTap?.call();
      },
      child: Container(
        alignment: Alignment.center,
        width: 100.w,
        height: 40,
        decoration: BoxDecoration(
          color: Theme.of(context).primaryColor,
          borderRadius: BorderRadius.all(
            Radius.circular(20.w),
          ),
        ),
        child: Text(
          widget.btnMsg ?? "刷新",
          style: HzyTextStyle.fontBold(
            size: 14.sp,
            color: HzyNormalColorS.colffffff,
          ),
        ),
      ),
    );
  }

  /// 触发方法
  ///
  ///
  Widget configPlaceWidget({
    int type = 1,
  }) {
    Widget? child = Container();
    switch (type) {
      case 1:
        child = createPlaceImageWidget();
        break;
      case 2:
        child = createPlaceTitleWidget();
        break;
      case 3:
        child = createPlaceMessageWidget();
        break;
      case 4:
        child = createPlaceReloadBtnWidget();
        break;
      default:
    }
    return child;
  }
}
